﻿Option Strict On
Option Explicit On 

Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.types

''' -----------------------------------------------------------------------------
''' Project	 : IPCommon
''' Class	 : Core.IPCommon.CDBUtils
''' 
''' -----------------------------------------------------------------------------
''' <summary>
''' Class này để giúp đỡ việc tạo các Oracle Command cho thuận tiện hơn.
''' Được sử dụng khi implement CStoredProc
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' 	[csung]	2/22/2005	Created
''' </history>
''' -----------------------------------------------------------------------------
Public Class CDBUtils
    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Trả lại 1 Decimal Input Param
    ''' </summary>
    ''' <param name="ip_name">tên, đối với oracle thì không cần "@" ở đầu</param>
    ''' <param name="ip_value">giá trị của tham số</param>
    ''' <returns></returns>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' 	[csung]	2/22/2005	Created
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Shared Function getDecimalInputParam(ByVal ip_name As String, _
                                         ByVal ip_value As Object) As OracleParameter
        Dim v_sqlPara As New OracleParameter
        v_sqlPara.OracleDbType = OracleDbType.Decimal
        v_sqlPara.Direction = ParameterDirection.Input
        v_sqlPara.Value = ip_value
        v_sqlPara.ParameterName = ip_name
        Return v_sqlPara
    End Function


    Public Shared Function getDecimalOutputParam(ByVal ip_name As String, _
                                                    ByVal ip_value As Object) As OracleParameter
        Dim v_sqlPara As New OracleParameter
        v_sqlPara.OracleDbType = OracleDbType.Decimal
        v_sqlPara.Direction = ParameterDirection.Output
        v_sqlPara.Value = ip_value
        v_sqlPara.ParameterName = ip_name
        Return v_sqlPara
    End Function

    Public Shared Function getDateTimeInputParam(ByVal ip_name As String, _
                                         ByVal ip_value As DateTime) As OracleParameter

        Dim v_sqlPara As New OracleParameter
        v_sqlPara.OracleDbType = OracleDbType.Date
        v_sqlPara.Direction = ParameterDirection.Input
        v_sqlPara.Value = ip_value
        v_sqlPara.ParameterName = ip_name
        Return v_sqlPara
    End Function

    Public Shared Function getDateTimeOutputParam(ByVal ip_name As String, _
                                                  ByVal ip_value As DateTime) As OracleParameter

        Dim v_sqlPara As New OracleParameter
        v_sqlPara.OracleDbType = OracleDbType.Date
        v_sqlPara.Direction = ParameterDirection.Output
        v_sqlPara.Value = ip_value
        v_sqlPara.ParameterName = ip_name
        Return v_sqlPara
    End Function

    Public Shared Function getVarcharInputParam(ByVal ip_name As String, _
                                         ByVal ip_value As String) As OracleParameter
        Dim v_sqlPara As New OracleParameter
        v_sqlPara.OracleDbType = OracleDbType.Varchar2
        v_sqlPara.Direction = ParameterDirection.Input
        v_sqlPara.Value = ip_value
        v_sqlPara.ParameterName = ip_name
        Return v_sqlPara
    End Function

    Public Shared Function getVarcharOutputParam(ByVal ip_name As String, _
                                     ByVal ip_value As Object, _
                                     Optional ByVal ip_size_of_value As Integer = 100) As OracleParameter

        Dim v_sqlPara As New OracleParameter
        v_sqlPara.OracleDbType = OracleDbType.Varchar2
        v_sqlPara.Direction = ParameterDirection.Output
        v_sqlPara.Value = ip_value
        v_sqlPara.ParameterName = ip_name
        v_sqlPara.Size = ip_size_of_value
        Return v_sqlPara
    End Function


End Class


